using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Input;
using DBAccessLibrary.Model;
using QueryResource.Common;
using QueryResource.ViewModel;

namespace BaseControlLibrary
{
    public class ContextMenuDataTemplateSelector : DataTemplateSelector
    {
        public override DataTemplate SelectTemplate(object item, DependencyObject container)
        {
            FrameworkElement element = container as FrameworkElement;
            DataTemplate template = null;
            if (element == null)
                return null;
            if (item is ServerEntity)
            {
                template = element.FindResource("ServerTemplate") as HierarchicalDataTemplate;
            }
            else if (item is DBEntity)
            {
                template = element.FindResource("DBTemplate") as HierarchicalDataTemplate;
            }
            else if (item is TableInfoEntity)
            {
                template = element.FindResource("TableInfoTemplate") as HierarchicalDataTemplate;
            }
            else if (item is IndexDescriptionEntity)
            {
                template = element.FindResource("IndexDescriptionTemplate") as HierarchicalDataTemplate;
            }
            else if (item is DescriptionEntity)
            {
                template = element.FindResource("DescriptionTemplate") as HierarchicalDataTemplate;
            }
            else if (item is TableEntity)
            {
                template = element.FindResource("TableTemplate") as HierarchicalDataTemplate;
            }
            else if (item is ProcParamEntity)
            {
                template = element.FindResource("ProcParamTemplate") as HierarchicalDataTemplate;
            }
            else if (item is FieldEntity)
            {
                template = element.FindResource("FieldTemplate") as HierarchicalDataTemplate;
            }
            else if (item is ProcEntity)
            {
                template = element.FindResource("ProcTemplate") as HierarchicalDataTemplate;
            }
            else if (item is ViewEntity)
            {
                template = element.FindResource("ViewTemplate") as HierarchicalDataTemplate;
            }
            else if (item is RelationshipEntity)
            {
                template = element.FindResource("ForeignTemplate") as HierarchicalDataTemplate;
            }
            else if (item is IndexEntity)
            {
                template = element.FindResource("IndexTemplate") as HierarchicalDataTemplate;
            }

            return template;
        }
    }
}
